import time
from time import sleep

from appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap={
              "platformName": "Android",
              "deviceName": "emulator-5554",
              "noReset": True,
              "appPackage": " com.achievo.vipshop",
              "appActivity": "com.achievo.vipshop.homepage.activity.MainActivity"
            }
        self.driver=webdriver.Remote('http://localhost:4723/wd/hub',cap)
        self.driver.implicitly_wait(20)
        sleep(10)
    def loc_ele(self,loc):
        return self.driver.find_element(*loc)
    def loc_ui_ele(self,loc):
        return self.driver.find_element_by_android_uiautomator(loc)
    def loc_quit(self):
        self.driver.quit()
    def loc_wait(self,loc):
        return WebDriverWait(self.driver,20).until(EC.presence_of_element_located(loc))
    def huoqu(self,loc,key):
        if type(loc)==str:
            t=self.loc_ele()
        else:
            t=self.loc_ui_ele()
        return t.get_attribute(key)
    def loc_huadong(self,x,y,x1,y1):
        self.driver.swipe(x,y,x1,y1,500)
    def loc_qingqiao(self,x,y):
        self.driver.tap([(x,y)],500)
    def jieping(self,filename):
        t=time.strftime('%Y%m%d%H%M%S',time.localtime())
        self.driver.save_screenshot(t+filename+'.png')